/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package common;

import java.awt.Toolkit;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JPanel;

/**
 *
 * @author Sony
 */
public class Common {

    public Common() {
    }

    public static void addPanel(JPanel panelMain, JPanel panel) {
        panelMain.removeAll();
        panelMain.setLayout(null);
        panel.setBounds(0, 0, panelMain.getWidth(), panelMain.getHeight());
        panelMain.add(panel);
        panelMain.updateUI();
        panelMain.setVisible(true);
    }

    public void setFullsize(JFrame frame) {
        Toolkit tk = Toolkit.getDefaultToolkit();
        int xSize = (int) tk.getScreenSize().getWidth();
        int ySize = (int) tk.getScreenSize().getHeight();
        frame.setSize(xSize, ySize);
        frame.setVisible(true);
    }

    public void setFullsizeDialog(JDialog dialog) {
        Toolkit tk = Toolkit.getDefaultToolkit();
        int widthSize = (int) tk.getScreenSize().getWidth();
        int heightSize = (int) tk.getScreenSize().getHeight();
        dialog.setSize(widthSize, heightSize);
        dialog.setVisible(true);
    }

    public boolean compareDate(Date beforDate, Date afterDate) {
        if (beforDate.equals(afterDate)) {
            return false;
        } else if (beforDate.before(afterDate)) {
            return true;
        } else {
            return false;
        }
    }

    public long dayBetween2Dates(Date beforDate, Date afterDate) {
        long noDay = (afterDate.getTime() - beforDate.getTime())
                / (24 * 3600 * 1000);
        return noDay;
    }

    public Date upDate(Calendar calendar, int i) {
        calendar.roll(Calendar.DAY_OF_YEAR, i);
        DateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
        Date date = calendar.getTime();
        return date;
    }

    public int checkBoolean(boolean choice) {
        if (choice) {
            return 1;
        } else {
            return 0;
        }
    }

    public Date convertStringToDate(String strDate) {
        Date date = null;
        DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
        try {
            date = dateFormat.parse(strDate);
        } catch (Exception ex) {
        }
        return date;
    }

    public String convertDateToString(Date utilDate) {
        String strDate = "";
        DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
        strDate = dateFormat.format(utilDate);
        return strDate;
    }

    public java.sql.Date convertDateUtilToSql(Date utilDate) {
        java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());
        return sqlDate;
    }

    public Date converDateSqlToUtil(java.sql.Date sqlDate) {
        Date utilDate = new Date(sqlDate.getTime());
        return utilDate;
    }
}
